Introduce sniff to avoid doing_it_wrong usage of register_block_type#347
Merged
Conversation
register_block_type internally delegates to register_block_type_from_metadata if a readable file path is passed, but if the file does not exist (usually from not having run a build) it throws a confusing doing_it_wrong message. We should be using register_block_type_from_metadata directly whenever we are not passing the name of a block as the first argument, since this can lead to wasted debugging time if the error is not understood correctly. This sniff attempts to put in place some heuristic detection for path-y first arguments passed to register_block_type, to catch this in PRs / CI.
Collaborator
Author
|
Tagging a few of you for feedback on whether this feels worth adding to our standard. It's something that's been a slight footgun even after trying to add agent instructions to support using the metadata version, and I'd like to be able to flag it at the PR stage automatically, without wasting human cycles on it — but it's technically already covered by a |
roborourke
approved these changes
Jul 7, 2026
roborourke
left a comment
Contributor
There was a problem hiding this comment.
It's a simple fix and if it avoids a common problem then it gets my vote.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
register_block_typeinternally delegates toregister_block_type_from_metadataif a readable file path is passed, but if the file does not exist (usually from not having run a build) it throws a confusing_doing_it_wrongmessage.We should be using
register_block_type_from_metadatadirectly whenever we are not passing the name of a block as the first argument, since this can lead to wasted debugging time if the error is not understood correctly.This sniff attempts to put in place some heuristic detection for path-y first arguments passed to
register_block_type, to catch this in PRs / CI.